package com.gitee.xmhzzz.mqtt.quick.controller;

import com.gitee.xmhzzz.mqtt.quick.client.MyMqttClient;
import com.gitee.xmhzzz.mqtt.quick.req.PublishReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName MqttController
 * @Description
 * @Author wzq
 * @Date 2024/1/14 15:40
 * @Version 1.0
 */
@Slf4j
@RequestMapping("/mqtt")
@RestController
public class MqttController {
    @Autowired
    private MyMqttClient myMqttClient;

    @PostMapping(value = "/publish")
    public String publishTopic(@RequestBody PublishReq req) {
        log.info("topic: {}",req.getTopic());
        log.info("message: {}", req.getSendMessage());
        this.myMqttClient.publish(false, req.getTopic(), req.getSendMessage());
        return "topic:" + req.getTopic() + "\nmessage:" + req.getSendMessage();
    }

}
